﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Web.UI.HtmlControls;

namespace areaUsuario.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPSite mySite = new SPSite("http://intranew.abdi.com.br");
            //SPSite mySite = new SPSite("http://intranetdev.abdi.com.br");
            SPWeb myweb = mySite.RootWeb;
            //SPWeb mySite = SPContext.Current.Web;
            SPList myList = myweb.Lists["Usuário"];
            SPListItemCollection itemCollection = myList.Items;


            SPUser usuario = myweb.CurrentUser;
            String userName = usuario.LoginName.ToLower();
            String varHTML ="";
            String[] words;       
            
            foreach (SPListItem item in itemCollection)
            {
                String verificaUsuario = item["Login"].ToString().Replace("abdi", "ABDI").ToLower();
                if (verificaUsuario == userName)
                {
                    words = item["Departamento"].ToString().Split('#');
                    varHTML += words[1].ToString();
                }
           }


            HtmlGenericControl div = (HtmlGenericControl)this.Page.FindControl("divmap");
            divmap.InnerHtml = varHTML;
        }
    }
}